package com.czy.ekp.gen.html;

import com.czy.ekp.gen.FieldVo;
import com.czy.ekp.gen.ModuleVo;
import com.czy.ekp.gen.TemplateCodeGenerator;
import freemarker.template.Template;

import java.util.HashMap;
import java.util.Map;

public class EditTemplateGenerator extends TemplateCodeGenerator {

    public EditTemplateGenerator(Template template) {
        super(template);
    }

    @Override
    public Map generateParameterMap(ModuleVo moduleVo) {

        HashMap params = new HashMap();

        boolean hasRichText = false;
        for(FieldVo field : moduleVo.getFields()){
            if(field.isKey()){
                field.setType("hidden");
            }
            if("richtext".equals(field.getType())){
                hasRichText = true;
            }
        }

        params.put("moduleName", moduleVo.getModuleName());
        params.put("key", moduleVo.getKeyField().getName());
        params.put("fields", moduleVo.getFields());
        params.put("hasRichText", hasRichText);

        return params;
    }
}
